import type {
  WetAirStateParameter,
  WetAirStateConfig,
  WetAirStateKeys,
} from '../types'

const wetAirState: Record<WetAirStateKeys, WetAirStateConfig> = {
  dryTemperature: {
    range: [-30, 100],
    message: '干球温度范围在-30℃到100℃之间!',
  },
  wetTemperature: {
    range: [-35, 100],
    message: '湿球温度范围在-35℃到100℃之间!',
  },
  dewTemperature: {
    range: [-40, 100],
    message: '露点温度范围在-40℃到100℃之间!',
  },
  enthalpy: {
    range: [-30, 1000],
    message: '比焓值范围在-30到1000之间!',
  },
  humidity: {
    range: [0, 300],
    message: '含湿量范围在0到300之间!',
  },
  relativeHumidity: {
    range: [0, 100],
    message: '相对湿度范围在0%到100%之间!',
  },
}

export default class ParameterValidator {
  static validate(params: WetAirStateParameter, pressure: number) {
    // Check if the number of parameters is 2
    if (pressure <= 0) {
      throw new Error('Invalid pressure')
    }
    const paramsCount = Object.keys(params).length

    if (paramsCount !== 2) {
      throw new Error('Invalid number of parameters')
    }

    Object.entries(params).forEach(([key, value]) => {
      const config = wetAirState[key as WetAirStateKeys]
      const [min, max] = config.range
      if (value < min || value > max) {
        throw new Error(config.message)
      }
    })
  }
}
